abcd = int(input())
if 9999>=abcd>=1000:
    pass
else:
    print(0)
    exit()
a=abcd//1000
b=abcd//100%10
c=abcd%100//10
d=abcd%10
l=[abcd,a,b,c,d]

l.append(a*10+b)
l.append(b*10+c)
l.append(c*10+d)
l.append(a*100+b*10+c)
l.append(b*100+c*10+d)
maxik=[]

for x in l:
    count = 0

    for i in range(2, x):
        if x % i == 0:
            count+=1
    if count==0:
        maxik.append(x)
if maxik==[]:
    print(0)
else:
    print(max(maxik))